<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="apple-mobile-web-app-status-bar-style" content="black" />
	<meta name="format-detection" content="telephone=no"/>
	<title>正在处理</title>
	<style>
	.loading {
		width: 130px;
		padding-top: 10px;
		padding: 10px;
		background: rgba(0,0,0,0.6);
		border-radius: 3px;
		margin: 250px auto;
		color: #fff;
		font-size: 12px;
		line-height: 14px;
		text-align: center;
	}
	.loading i {
			margin: 0 auto;
			display: block;
			width:33px;
			height: 33px;
			background: url(img/load.png) center no-repeat;
			background-size: 33px 33px; 
			margin-bottom: 10px;
			-webkit-animation-name: loading;
			-webkit-animation-duration: 1.4s;
			-webkit-animation-iteration-count: infinite;
			-webkit-animation-timing-function: linear;
		}

		@-webkit-keyframes loading {
			from { -webkit-transform: rotate(0deg) translateZ(0); }
			to { -webkit-transform: rotate(360deg) translateZ(0); }
		}
	</style>
</head>
<body>
	<div class="loading">
		<i></i>
		正在处理，请稍后...
	</div>
</body>
<script src="js/common.js"></script>
<script src="js/jquery.js"></script>
	<script>
		var code = getQueryString('code');
		/*
		 * state 参数定义
		 * 1 : 组训社区
		 * 2 : 讲师CLUB
		 * 3 : 回复绑定关键字
		 * 4 : 三陪九辅
		 */
		var state = getQueryString('state');

		//组训社区认证
		function getInfo(){
			$.ajax({
		        cache: false,
		        type: "GET",
				dataType: "JSON",
		        url:API_URL+"agent/getuser?code="+code,  //此处需要将API_URL写全局
		        async: false,
		        success: function(jsonobj) {
		        	if(jsonobj.status.code == 0){
						//已认证,跳转主页,将openid传入
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						window.location = 'program/person_mainpage.html?openid='+openid;
					}

					if(jsonobj.status.code == 1){
						//未认证,跳转认证页面,将openid传入
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						window.location = 'validate.html?openid='+openid+'&state='+state;
					}

					if(jsonobj.status.code == -1){
						//错误,跳转错误页面,500
						window.location = 'error.html';
					}

					if(jsonobj.status.code == 2){
						//已认证, 但不是督训/组训成员
						alert('您不是督训/组训成员!');
						window.location = 'error.html';
					}
		        },
				error: function(request) {
		            //跳转错误页面
					window.location = 'error.html';
		        }
		    });
		}


		//讲师CLUB认证
		function getTeacher(){
			$.ajax({
		        cache: false,
		        type: "GET",
				dataType: "JSON",
		        url:API_URL+"agent/getteacher?code="+code,
		        async: false,
		        success: function(jsonobj) {
		        	if(jsonobj.status.code == 0){
						//已认证,讲师
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						window.location = 'teacherclub/ranking_list.html?openid='+openid+'&user_status=1&agentid='+myData.id;
					}

					if(jsonobj.status.code == 1){
						//未认证,将openid传入
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						window.location = 'teacherclub/ranking_list.html?openid='+openid+'&user_status=3';
					}

					if(jsonobj.status.code == -1){
						//错误,跳转错误页面,500
						window.location = 'error.html';
					}

					if(jsonobj.status.code == 2){
						//已认证,非讲师
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						window.location = 'teacherclub/ranking_list.html?openid='+openid+'&user_status=2';
					}
		        },
				error: function(request) {
		            //跳转错误页面
					window.location = 'error.html';
		        }
		    });
		}

		
		//回复绑定关键字
		function getBangding(){
			$.ajax({
		        cache: false,
		        type: "GET",
				dataType: "JSON",
		        url:API_URL+"agent/getBangding?code="+code,
		        async: false,
		        success: function(jsonobj) {
		        	if(jsonobj.status.code == 0){
						//已认证
						alert('您已经认证身份!');
						window.location = 'error.html';
					}

					if(jsonobj.status.code == 1){
						//未认证
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						window.location = 'validate.html?openid='+openid+'&state='+state;
					}

					if(jsonobj.status.code == -1){
						//错误,跳转错误页面,500
						window.location = 'error.html';
					}

					if(jsonobj.status.code == 2){
						//已认证,非讲师
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						window.location = 'teacherclub/ranking_list.html?openid='+openid+'&user_status=2';
					}
		        },
				error: function(request) {
		            //跳转错误页面
					window.location = 'error.html';
		        }
		    });
		}

		/*
		 * 三陪九辅认证
		 */
		function getSpjf(){
			$.ajax({
		        cache: false,
		        type: "GET",
				dataType: "JSON",
		        url:API_URL+"manager/getSpjf?code="+code,
		        async: false,
		        success: function(jsonobj) {
		        	if(jsonobj.status.code == 0){
						//已认证,新人
						//alert('您已经认证身份!');
						var myData = jsonobj.data[0];
						var userId = myData.staff_number;
						window.location = 'newCustomsClearance/growth_recorded.html?userId='+userId;
					}

					if(jsonobj.status.code == 1){
						//未认证
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						window.location = 'validate.html?openid='+openid+'&state='+state;
					}

					if(jsonobj.status.code == -1){
						//错误,跳转错误页面,500
						window.location = 'error.html';
					}

					if(jsonobj.status.code == 2){
						//已认证,不是新人
						var myData = jsonobj.data[0];
						var userId = myData.staff_number;
						window.location = 'newCustomsClearance/growth_index.html?userId='+userId;
					}
		        },
				error: function(request) {
		            //跳转错误页面
					window.location = 'error.html';
		        }
		    });
		}


		function showload(){
			//alert(code);
			if(code==''){
				alert('获取用户授权失败!');
				return;
			}

			if(state=='1'){
				getInfo();
			}
			
			if(state=='2'){
				getTeacher();
			}

			if(state=='3'){
				getBangding();
			}

			if(state=='4'){
				//三陪九辅
				getSpjf();
			}
		}

		showload();
	</script>
</html>